package org.ethereum.net.dpos;

import org.ethereum.net.message.Message;
import org.ethereum.net.message.MessageFactory;

/**
 * DPOS message factory
 *
 * @author Shaolin Wu
 * @since 03/10/2018
 */
public class DPOSMessageFactory implements MessageFactory {

    @Override
    public Message create(byte code, byte[] encoded) {

    		DPOSMessageCodes receivedCommand = DPOSMessageCodes.fromByte(code);
        switch (receivedCommand) {
            case VOTE_PRESIDENT_REQUEST:
                return new VotePresidentRequest(encoded);
            case VOTE_PRESIDENT_RESPONSE:
                return new VotePresidentResponse(encoded);
            case VOTE_PRESIDENT_BROADCAST:
                return new VotedPresidentBroadcast(encoded);
            case PACKAGE_REQUEST:
                return new PackageRequest(encoded);
            case PACKAGE_RESPONSE:
                return new PackageResponse(encoded);
            case RegisterCandidateREQUEST:
                return new RegisterCandidateRequest(encoded);
            case RegisterCandidateRESPONSE:
                return new RegisterCandidateResponse(encoded);
            case CONFIRMED_BLOCK_SYNC:
                return new ConfirmedSyncMessage(encoded);
            default:
                throw new IllegalArgumentException("No such message");
        }
    }
}
